package com.czr.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.czr.constant.isLogin;
import com.czr.dao.service.CzrUserService;
import com.czr.dto.Search;
import com.czr.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Slf4j
@Api(value = "会员功能", tags = "会员功能")
@RestController
@RequestMapping("/member")
public class MemberController {

    @Autowired
    private CzrUserService userService;

    @Resource
    private RedisTemplate<Object, Object> redisTemplate;

    @isLogin
    @ApiOperation(value = "会员列表", notes = "会员列表")
    @PostMapping("/list")
    public Result<Object> list(@RequestBody Search search) {
        try {
            return userService.list(search);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail();
        }

    }
//    @ApiOperation(value = "会员介绍", notes = "会员介绍")
//    @ApiImplicitParams({
//            //参数效验
//            @ApiImplicitParam(name="uuid",value="会员标识",required=true,dataType="Integer")
//    })
//    @GetMapping("/getUserInfo")
//    public Result<Object> getUserInfo(@RequestParam String uuid, HttpServletRequest request) {
//        try {
//            ValueOperations<Object, Object> valueOperations = redisTemplate.opsForValue();
//            Object object=valueOperations.get(request.getHeader("token"));
//            if (!StringUtils.isEmpty(object)) {
//                JSONObject cacheToken = JSON.parseObject(object.toString());
//                Result<Object> result = userService.getUserInfoMember(uuid,cacheToken);
//                return result;
//            } else {
//                Result<Object> result = userService.getUserInfoMember(uuid,null);
//                return result;
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            return Result.fail();
//        }
//    }

}
